package com.bjpowernode.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class Myutil {

    public static SqlSessionFactory factory;    //必须定义为全局变量

    static{
        String config = "mybatis.xml";
//        SqlSessionFactory factory;

        try {
            InputStream inp = Resources.getResourceAsStream(config);
            factory = new SqlSessionFactoryBuilder().build(inp);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static SqlSession getSqlSession(){
        SqlSession sqlSession = null;
        if(factory!=null){
            SqlSession sqlSession1 = factory.openSession();

        }
        return sqlSession;
    }
}
